n, m = [int(i) for i in input().split()]
hints = [input() for _ in range(m)]
l = [0 for i in range(n)]
total = 0
for h in hints:
s = h.split()
if "right" in s:
for i in range(0, int(s[-1])): l[i] = -1
if "left" in s:
for i in range(int(s[-1])-1, n): l[i] = -1
for i in l:
if i == 0: total += 1
if total == 0: print(-1)
else: print(total)
#pragma GCC optimization("Ofast")
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define ELZOMOR cin.tie(0)->sync_with_stdio(0);
#define ll long long
using namespace std;
void file() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
cin.tie(0)->sync_with_stdio(0);
#endif
}
ll mod = 1e9;
ll N = 1e6 + 5;
ll fact[(int)1e6 + 5];
ll inv[(int)1e6 + 5];
ll PowMod(ll x, ll y) {
ll res = 1;
while (y) {
if (y & 1) res = (res * x) % mod;
y >>= 1, x = (x * x) % mod;
}
return res;
}
void pre() {
fact[0] = inv[0] = 1;
for (ll i = 1; i < N; i++)
fact[i] = (fact[i - 1] * i) % mod,
inv[i] = PowMod(fact[i], mod - 2);
}
ll a, b, c, n, r, q, m, h,x,y, k;
ll modInv(ll n) {
return PowMod(n, mod - 2);
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
int DR[] = { 0,0,-1,1 };
int DC[] = { 1,-1,0,0 };
char arr[1000 + 2][1000 + 2];
int vis[1000 + 2][1000 + 2];
int f = 0;
void solve() {
string one, two, three, four, five;
cin >> n >> m;
int lm = 1,rr=n;
for (int i = 0; i < m; i++)
{
cin >> one >> two >> three >> four >> five;
if (three == "right") {
lm = max(lm,stoi(five) + 1);
}
else if (three == "left") {
rr = min(stoi(five) - 1,rr);
}
}
if (lm<1 || rr>n||lm>rr) { cout << -1; return; }
cout << (rr - lm+1 );
}
int main() {
file();
ELZOMOR;
int t = 1;
//cin>>t;
while (t--) {
solve();
}
}
1618A - Polycarp and Sums of Subsequences | 1618B - Missing Bigram |
938. Range Sum of BST | 147. Insertion Sort List |
310. Minimum Height Trees | 2110. Number of Smooth Descent Periods of a Stock |
2109. Adding Spaces to a String | 2108. Find First Palindromic String in the Array |
394. Decode String | 902. Numbers At Most N Given Digit Set |
221. Maximal Square | 1200. Minimum Absolute Difference |
1619B - Squares and Cubes | 1619A - Square String |
1629B - GCD Arrays | 1629A - Download More RAM |
1629C - Meximum Array | 1629D - Peculiar Movie Preferences |
1629E - Grid Xor | 1629F1 - Game on Sum (Easy Version) |
2148. Count Elements With Strictly Smaller and Greater Elements | 2149. Rearrange Array Elements by Sign |
2150. Find All Lonely Numbers in the Array | 2151. Maximum Good People Based on Statements |
2144. Minimum Cost of Buying Candies With Discount | Non empty subsets |
1630A - And Matching | 1630B - Range and Partition |
1630C - Paint the Middle | 1630D - Flipping Range |